#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;

int arr[1024][1024] = {0};
void copy(int a, int b, int new_a, int new_b, int size)
{
    for (int i = 0; i < size; i++)
    {
        /* code */
        for (int j = 0; j < size; j++)
        {
            arr[new_a + i][new_b + j] = arr[a + i][b + j];
        }
    }
}
void table(int i, int j, int n)
{
    if (n > 1)
    {
        table(i, j, n / 2);
        table(i + n / 2, j, n / 2);
        copy(i, j, i + n / 2, j + n / 2, n / 2);
        copy(i + n / 2, j, i, j + n / 2, n / 2);
    }
}
int main()
{
    //初始化
    int n = 8;
    cout << "please input(2^k):" << endl;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        // cout<<1-1<<endl;
        arr[i][0] = i + 1;
        arr[0][i] = i + 1;
    }
    //空白表输出
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }
    table(0, 0, n);
    cout << endl;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }

    system("pause");
    return 0;
}
